<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="头像" prop="avatar">
        <UploadImg v-model="form.avatar" @avatarCheck="avatarCheck" />
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username" />
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="submit">确定</el-button>
    <el-button type="primary" @click="avatarCheck">部分表单验证</el-button>

  </div>
</template>
<script>
import UploadImg from '@/components/uploadImg'
export default {
  components: {
    UploadImg
  },
  data() {
    return {
      form: {
        avatar: '',
        username: ''
      },
      rules: {
        avatar: [{
          required: true, message: '必填', trigger: 'change'
        }],
        username: [{
          required: true, message: '必填', trigger: 'change'
        }]
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate((result) => {
        console.log(result)
      })
    },
    avatarCheck() {
      this.$refs.form.validateField(['avatar'])
    }
  }
}
</script>
<style>
</style>
